<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/24 0024
 * Time: 15:00
 */
//https://blog.csdn.net/m0_38080126/article/details/77187920



$descriptorspec=array(
    0=>STDIN,
    1=>STDOUT,
    2=>STDERR
);
//define('STDIN', fopen('php://stdin', 'r'));
//define('STDOUT', fopen('php://stdout', 'w'));
//define('STDERR', fopen('php://stderr', 'w'));
//$descriptorspec = array(
//    0 => array('pipe', 'r'),
//    1 => array('pipe', 'w'),
//    2 => array('pipe', 'w'),
//);

$process = proc_open('mysql -u root -pAbc123!Abc', $descriptorspec, $pipes);
//var_dump($pipes);
if (is_resource($process)) {
    fwrite($pipes[0], 'content');
    fclose($pipes[0]);
    while ($ret = fgets($pipes[1])) {
        echo $ret . PHP_EOL;
    }
    fclose($pipes[1]);
    while ($ret = fgets($pipes[2])) {
        echo $ret;
    }
    fclose($pipes[2]);
    proc_close($process);
}
//if (is_resource($process)) {
//    fwrite($pipes[0], "content\n\r");
//    $ret = fgets($pipes[1]);
//    echo $ret . PHP_EOL;
//    $ret = fgets($pipes[2]);
//    echo $ret . PHP_EOL;
//
//}